home *** CD-ROM | disk | FTP | other *** search
- /* adapted from Larry Gritz's antialiased screen shader (see BMRTShaders/BMAntialiasedScreen and RCGlow)
- */
- /*
- * WWGrid.sl -- shader that makes a glowing screen with potentially different grids in s and t
- *
- * DESCRIPTION:
- * Makes a surface that looks like a glowing screen. Strips of metal run
- * parallel to lines of s and t. You can adjust the Ka, Kd, Ks, etc.
- * to change the material appearance. This texture antialiases pretty
- * well, even with only one sample per pixel.
- *
- * PARAMETERS:
- * Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader
- * frequency - how many cycles of screen in st space
- * density - how much of each cycle is opaque?
- *
- * AUTHOR: hacked by wave (again, from an original shader by Larry Gritz)
- *
- */
-
-
-
- #define boxstep(a,b,x) (clamp(((x)-(a))/((b)-(a)),0,1))
- #define MINFILTERWIDTH 1.0e-7
-
-
-
- surface
- WWGlowingGrid (float Ka = 1, Kd = 0.75, Ks = 0.4, roughness = 0.1;
- color specularcolor = 1;
- float sDensity = 0.2, sFrequency = 2,
- tDensity = .1, tFrequency = 10,
- attenuation = 2)
- {
- point Nf; /* Forward facing Normal vector */
- point IN; /* normalized incident vector */
- float d; /* Density at the sample point */
- float ss, tt; /* s,t, parameters in phase */
- float swidth, twidth, sGWF, tGWF, w, h;
- point NN = normalize(N);
- point II = normalize(I);
- float falloff = II.NN; /* Direct incidence has cosine closer to 1.*/
-
-
- /* Compute a forward facing normal */
- IN = normalize (I);
- Nf = faceforward (normalize(N), I);
-
- /* Determine how wide in s-t space one pixel projects to */
- swidth = max (abs(Du(s)*du) + abs(Dv(s)*dv), MINFILTERWIDTH) * sFrequency;
- twidth = max (abs(Du(t)*du) + abs(Dv(t)*dv), MINFILTERWIDTH) * tFrequency;
-
- /* Figure out where in the pattern we are */
- ss = mod (sFrequency * s, 1);
- tt = mod (tFrequency * t, 1);
-
- /* Figure out where the strips are. Do some simple antialiasing. */
- sGWF = sDensity*0.5;
- if (swidth >= 1)
- { w = 1 - 2*sGWF;
- }
- else
- { w = clamp (boxstep(sGWF-swidth, sGWF, ss), max(1-sGWF/swidth, 0), 1)
- - clamp (boxstep(1-sGWF-swidth, 1-sGWF, ss), 0, 2*sGWF/swidth);
- }
-
- tGWF = tDensity*0.5;
- if (twidth >= 1)
- { h = 1 - 2*tGWF;
- }
- else
- { h = clamp (boxstep(tGWF-twidth, sGWF, tt), max(1-tGWF/twidth, 0), 1)
- - clamp (boxstep(1-tGWF-twidth, 1-tGWF, tt), 0, 2*tGWF/twidth);
- }
-
- d = 1 - w*h;
- Oi = d;
- if (d > 0)
- { if (falloff < 0)
- { /* Back of sphere only */
- /* Normalize falloff by lengths of I and N */
- falloff = falloff * falloff / (II.II * NN.NN) ;
- falloff = pow(falloff, attenuation);
- Ci = Cs * falloff;
- Oi = falloff;
- }
- else
- { Oi = 0;
- Ci = 0; /* wave added this line to avoid old bug in rendrib... */
- }
- }
- else
- { Oi = 0;
- Ci = 0; /* wave added this line to avoid old bug in rendrib... */
- }
- }
-